package com.baselibrary.utils;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

public class GridSpacesRightNoEndDec extends RecyclerView.ItemDecoration {
    private int space;
    private int count;

    public GridSpacesRightNoEndDec(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        GridLayoutManager.LayoutParams params = (GridLayoutManager.LayoutParams) view.getLayoutParams();
        // 获取item在span中的下标
        int spanIndex = params.getSpanIndex();
        if (spanIndex % 2 == 0) {
            outRect.right = space;
        } else {
            outRect.right = 1;
        }
    }
}